<template>
    <div class="m-window"> 
         <el-row :gutter="10" style="margin:8px auto;">
             <el-col :span="2">
                <el-button type="primary" @click="backToMyList">返回</el-button>
            </el-col>
            <el-col :span="2" v-show="pageSourceCode != 'myProcessed'">
                <el-button type="primary" @click="sendBack">退回</el-button>
            </el-col>
            <el-col :span="2" v-show="pageSourceCode != 'myProcessed'">
                <el-button type="primary" @click="pass">通过</el-button>
            </el-col>
            
        </el-row>
        <div class="package-col">
             <browse-contract
                :account="account"
                :applyId="applyId"
                :contentColHeight="contentColHeight"/>
        </div>
        <el-row style="margin-top:20px;">
            <el-col>
                 <el-form :model="lawWorksAForm" ref="lawWorksAForm">
                    <el-form-item prop="note" style="margin-top:-8px;">
                        <label>退回原因 &nbsp;<i class="el-icon-warning"></i></label>
                        <el-input type="textarea" v-model.trim="lawWorksAForm.note" placeholder="退回原因" :disabled="pageSourceCode == 'myProcessed'" />
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
   </div>
</template>
<style lang="less" scoped>
    .m-window{
        overflow: auto;
        overflow-x: hidden;
        .package-col{
            position:relative;
            width: 100%;
            height: auto;
        }
    }
</style>
<script>
import { showAlert } from "lesso-common/public/utils"
import { mapState,mapActions } from 'vuex'

export default {
    props:['pageSourceCode'],
    data(){
        return {
            checkTab:'',
            contentColHeight:680,
            lawWorksAForm:{
                result:1, //0 未到达、1 待审批、2 通过 、3 退回
                note:'' //退回原因
            },
            examinePass:2, //2 通过
            examineNotgo:3, //3 退回
            linkName:'act_fin_review', //流程环节名称
            account:'', //电子签账号
            applyId:'', //申请ID
            flowStepCode:0, //步骤码
        }
    },
    created(){
        this.account = this.supplyChainFinance.role.eSignAccount//使用供应商的电子签账号，这样才只能预览合同
        this.applyId = this.supplyChainFinance.role.ID    
    },
    computed: {
        ...mapState(['supplyChainFinance'])
    },
    methods:{
         ...mapActions([
            'changeTOdo',
            'changeMyProcessedCTCode'
        ]),
        async commonUpdate(){
            let that = this
            let parameter = Object.assign({},{
                name:that.linkName,
                applyId:that.applyId
            },that.lawWorksAForm)
            await that.$http.commonUpdate(parameter).then(({data})=>{
                if(data.code == 200){
                    showAlert({
                        msg: `操作成功！`,
                        type: 1
                    })
                   that.changeTOdo({isMyToDoList:that.flowStepCode})
                }else{
                    showAlert({
                        msg: `操作失败：${data.info}`,
                        type: 0
                    })
                }
            })
            .catch((error)=>{
                this.$alert("查询失败，请检查网络！", {
                    confirmButtonText: "确定",
                    customClass: "alertFailure"
                })
            })
        },
        pass(){        
            this.$confirm('是否确认通过？').then(_ => {
                    this.lawWorksAForm.result = this.examinePass
                    this.lawWorksAForm.note = ''
                    this.flowStepCode = 0
                    this.commonUpdate()
                })
                .catch(_ => {})
        },
        sendBack(){
            if(!this.lawWorksAForm.note){
                 showAlert({
                    msg: "请填写退回原因",
                    type: 2
                })
                return
            }
            this.$confirm('是否确认退回？').then(_ => {
                this.lawWorksAForm.result = this.examineNotgo
                this.flowStepCode = 0
                this.commonUpdate()
            })
        },
        backToMyList(){
            if(this.pageSourceCode == 'myProcessed'){
                this.changeMyProcessedCTCode('')
            }else{
                this.changeTOdo({isMyToDoList:0})
            }             
        } 
    }
}
</script>
